﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Level : Form
    {
        const string BaseDir = @"..\..\Information";        
        public static string filename;
        
        public Level()
        {
            InitializeComponent();

            int index = 0;
            while (File.Exists(BaseDir+"\\Information" + (index+1).ToString() + ".txt"))
            {                
                
                var newRb = new RadioButton();
                
                newRb.Location = new Point(33 + (index % 5) * 95, 80 + (index / 5) * 80);
                newRb.Width = 50;
                newRb.Height = 50;
                newRb.CheckedChanged += new EventHandler(rb_CheckedChanged);
                newRb.Tag = (index+1);
                newRb.Text = (index + 1).ToString();
                newRb.BackgroundImage = Properties.Resources.BackgroundImage;
                if (index >= Settings.MaxLevel)
                    newRb.Enabled = false;

                Controls.Add(newRb);
                
                index++;
            }
        }
                
        public int k=0;

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MainForm main = new MainForm();
                main.Show();
                this.Hide();
            }
            catch { MessageBox.Show("Уровень не выбран!","Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); }

        }

        private void rb_CheckedChanged(object sender, EventArgs e)
        {
            int index = (int)((Control)sender).Tag;
            filename = BaseDir + "\\Information" + index.ToString() + ".txt";
            Settings.SelectedLevel = index;
        }

        private void Level_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Menu men = new Menu();
            this.Hide();
            men.Show();
        }

                                    
    }
}
